<?php
/**
 * @package Autogenerator for Joomla!
 * @version 3.0.0
 * @author Truong Cong Duc <truongcongduc4@gmail.com>
 * @link autogenerator.blogspot.com
 * @copyright (c) 2013, Truong Cong Duc
 * @license GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

class AutogeneratorTableComponent extends JTable {

    public function __construct(&$db) {
        parent::__construct('#__auto_component', 'id', $db);
    }
    
    
    public function checkTitleValid($sTitle) {
        $sRegex = '/^[A-Za-z0-9_]+$/';

        if (!preg_match($sRegex, $sTitle))
            return false;

        return true;
    }
    
    public function check() {
        $this->title = str_replace(' ', '_', trim($this->title));
        
        if (!$this->checkTitleValid($this->title)) {
            $this->setError(JText::_('COM_AUTOGENERATOR_COMPONENT_ERROR_MESSAGE_COMPONENT_TITLE_NOT_VALID'));
            return false;
        }
        
        return true;
    }

}
